package com.rzjm.api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.rzjm.api.dao.ChargerManagerMapper;
import com.rzjm.api.entity.ChargerManager;
import com.rzjm.api.service.ChargerManagerService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 一体机的管理员Service业务层处理
 *
 * @author ruoyi
 * @date 2022-06-24
 */
@Service
public class ChargerManagerServiceImpl extends BaseServiceImpl<ChargerManagerMapper, ChargerManager> implements ChargerManagerService {

    @Resource
    private ChargerManagerMapper chargerManagerMapper;

    @Override
    public long getDeviceCountByUserId(int userId) {
        QueryWrapper<ChargerManager> qw = new QueryWrapper<>();
        qw.eq("user_id",userId);
        return chargerManagerMapper.selectCount(qw);
    }

    @Override
    public ChargerManager getManagerByUserId(int userId, int deviceId) {
        QueryWrapper<ChargerManager> qw = new QueryWrapper<>();
        qw.eq("user_id",userId);
        qw.eq("charger_id",deviceId);
        qw.last("limit 1");
        return chargerManagerMapper.selectOne(qw);
    }
}
